home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 24
/
Amiga Format AFCD24 (Feb 1998, Issue 108).iso
/
-in_the_mag-
/
emulation
/
-otherstuff-
/
amiganpi
/
src_blitz
/
amiganpi.asc
next >
Wrap
Text File
|
1998-01-05
|
5KB
|
197 lines
; Amiga Newton Package Installer
; version 1.4
; DON'T set overflow checking when compiling
; as Blitz2 doesn't like trying to poke.b a,255
; (probably because 255 is an invalid signed byte value)
#debug=0
#cli_only=0 ; set to 1 if CLI-only version
CNIF #cli_only=0
WBStartup
CEND
;SetErr:End:End SetErr
; default value of variables, may be altered by CLI arguments,
; preference file or MUI interface
package$=""
package_length.l=0
device$="devs:serial.device"
device_unit.l=0
device_buffer.l=64
device_speed.l=38400
device_flags.l=148 ; Xon/Xoff disabled, high speed and RTS/CTS
desk_wait.l=30
newt_wait.l=5
INCDIR "temp:programming/AmigaNPI/"
XINCLUDE "Interface.bb2"
;strangely enough, only one DIR can be the INCDIR at a time!
INCDIR "temp:programming/AmigaNPI/"
XINCLUDE "crc16.bb2"
INCDIR "temp:programming/AmigaNPI/"
XINCLUDE "fram.bb2"
;main routine
lt$="newtdockdock"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4)
lt2$="newtdockstim"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(newt_wait)
lt3$="newtdocklpkg"+Chr$(0)+Chr$(0)+Chr$($2f)+Chr$($a0)
lt4$="newtdockdisc"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)
buf$=String$(" ",128)
still_running=True
CNIF #cli_only=0
If gui_on Then still_running=get_gui_args{}
CEND
While still_running
timeout=False
If OpenSerial (device$,device_unit,device_speed,device_flags)
SetSerialBuffer device_unit,device_buffer
If ReadFile(0,package$)
Poke.l <3$+12,Lof(0)
Notify_Waiting{}
dummy.l=waitConnection{}
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_Connecting{}
dummy.l=receiveData{&buf$,Len(buf$)} ;newtdockrtdk
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_rtdk{}
dummy.l=sendData{<$,Len(lt$)} ;newtdockdock
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_dock{}
dummy.l=receiveData{&buf$,Len(buf$)} ;newtdockname
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_name{&buf$,dummy}
dummy.l=sendData{<2$,Len(lt2$)} ;newtdockstim
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_timeoutset{}
dummy.l=receiveData{&buf$,Len(buf$)} ;newtdockdres
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_resultreceived{}
file_length.l=Lof(0)
Notify_loading{package$}
Notify_filelength{file_length}
dummy.l=sendData{<3$,Len(lt3$)} ;newtdocklpkg
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_transferring{}
ReadMem 0,&buf$,Len(buf$)
rr.l=0
size.l=0
If Lof(0)<Len(buf$)
rr=Lof(0)
Else
rr=Len(buf$)
EndIf
size=rr
Notify_progress{size}
dummy.l=sendData{&buf$,rr}
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
While (rr=Len(buf$)) AND (timeout=False)
ReadMem 0,&buf$,Len(buf$)
If Eof(0)
rr=file_length-size ;reading the file length lof(0) at
;this point results in an error because lof(0) is
Else ;one more byte than the file's true size!
rr=Len(buf$)
EndIf
size+rr
Notify_progress{size}
If (rr&3)>0 ;file length is not an evenly divisible by four
Notify_padding{}
rr2.l=(rr+4)&$fffffffc ;round up file length
For i=rr+1 To rr2 ;fill with zeros
Poke &buf$+i,0
Next i
rr=rr2
EndIf
If rr>0 Then dummy.l=sendData{&buf$,rr}
If dummy<-1 Then timeout=True
Wend
If timeout=True Then Goto timeout_jump ; flag tripped by data sending routine
Notify_finished{}
dummy.l=receiveData{&buf$,Len(buf$)} ; newtdockdres
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_resultreceived{}
dummy.l=sendData{<4$,Len(lt4$)} ; newtdockdisc
If dummy<-1
timeout=True
Goto timeout_jump
EndIf
Notify_disconnecting{}
VWait 50
sendDisconnect{}
timeout_jump:
If timeout=True
Notify_timeout{}
EndIf
Notify_disconnected{}
CloseFile 0
Else
Notify_nofile{}
EndIf
While ReadSerial(0)>=0:Wend ; flush out the input buffer
CloseSerial 0
Else
Notify_noserial{}
EndIf
CNIF #cli_only=0
If gui_on
still_running=get_gui_args{}
Else
CEND
still_running=False ; only run once if CLI arguments used
CNIF #cli_only=0
EndIf
CEND
Wend
End